package com.kim.common.resp;

/**
 * 各种错误对象
 *
 */
public class CodeMsg {


    /**
	 * 错误码
	 */
	private int code;
	
	/**
	 * 错误信息
	 */
	private String msg;

	/** 通用的错误码 */
	public final static CodeMsg SUCCESS = new CodeMsg(0, "success");
	
	/** 其他异常 */
	public final static CodeMsg LOGIN_FAIL = new CodeMsg(-1,"请登录");
	public final static CodeMsg LOGIN_TIMEOUT = new CodeMsg(1,"登录状态超时，请登录");
	public final static CodeMsg ERROR_SYSTEM = new CodeMsg(2, "系统繁忙！");
	public final static CodeMsg SPEED_FAST = new CodeMsg(3, "刷新太快啦");
	public final static CodeMsg PARAM_FAIL = new CodeMsg(4, "无效参数");

	public final static CodeMsg ANALYSIS_DATE_ERROR = new CodeMsg(9, "时间解析错误");


	public final static CodeMsg UPDATE_FAIL = new CodeMsg(20, "更新失败");
	public final static CodeMsg SAVE_FAIL = new CodeMsg(21, "保存失败");
	public final static CodeMsg DELETE_FAIL = new CodeMsg(22, "删除失败");



	public final static CodeMsg ACOUNT_NOT_FOUND = new CodeMsg(101,"用户名不存在");
	public final static CodeMsg PASSWORD_NOT_FOUND = new CodeMsg(102,"密码不正确");
	public final static CodeMsg USER_NOT_PERMISSTION = new CodeMsg(103,"用户未授权");

	public final static CodeMsg USER_NOT_EXIST = new CodeMsg(151,"用户不存在");
	public final static CodeMsg USER_NAME_EXIST = new CodeMsg(151,"用户已存在，请勿重复添加");
	public final static CodeMsg ROLE_NAME_EXIST = new CodeMsg(151,"角色已存在，请勿重复添加");

	public final static CodeMsg METHOD_FALLBACK = new CodeMsg(201,"相应失败，进行服务降级");

	public final static CodeMsg TX_LCN_BACK = new CodeMsg(251,"事务回滚");



	public CodeMsg() {
	}

	public CodeMsg(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	/**
	 * 添加额外信息，例如：BIND_ERROR这种
	 * @param args
	 * @return
	 */
	public CodeMsg fillArgs(Object... args) {
		int code = this.code;
		String message = String.format(this.msg, args);
		return new CodeMsg(code, message);
	}

	@Override
	public String toString() {
		return "CodeMsg [code=" + code + ", msg=" + msg + "]";
	}

}
